<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>添加物资</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">物资编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="materialCode" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入物资编号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">物资名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="materialName" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入物资名称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">规格</label>
                        <div class="layui-input-block">
                            <input type="text" name="model" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入规格" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="type" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入类型" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">采购价格</label>
                        <div class="layui-input-block">
                            <input type="text" name="purchasePrice" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入采购价格" class="layui-input">
                        </div>
                    </div> 
                    <div class="layui-form-item">
                        <label class="layui-form-label">零售价格</label>
                        <div class="layui-input-block">
                            <input type="text" name="retailPrice" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入零售价格" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">制造商</label>
                        <div class="layui-input-block">
                            <input type="text" name="manufacturer" value="" lay-verify="required" autocomplete="off"
                                placeholder="请输入制造商" class="layui-input">
                        </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit=""
                    lay-filter="user-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    <script src="../../../component/layui/layui.js"></script>
    <script src="../../../component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery', 'transfer', 'layer', 'util'], function () {
            let form = layui.form;
            var $ = layui.$;
            var transfer = layui.transfer;
            var layer = layui.layer;
            var util = layui.util;



            form.on('submit(user-save)', function (data) {

                $.ajax({
                    url: 'http://localhost:8080/material/add',
                    data: data.field,
                    type: 'post',
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader('token', localStorage.getItem("token"));
                    },
                    success: function (result) {
                        if (result.code == 0) {
                            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                parent.layui.table.reload("user-table");
                            });
                        } else {
                            layer.msg(result.msg, { icon: 2, time: 1000 });
                        }
                    }
                })

                return false;
            });
        })
    </script>
    <script>
    </script>
</body>

</html>